package com.liaozl.sca.order.controller;

import com.liaozl.sca.account.dto.AccountDTO;
import com.liaozl.sca.account.feign.AccountFeign;
import com.liaozl.sca.common.dto.Result;
import com.liaozl.sca.order.dto.OrderDTO;
import com.liaozl.sca.order.feign.OrderFeign;
import com.liaozl.sca.user.dto.UserDTO;
import com.liaozl.sca.user.feign.UserFeign;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description:
 * @version: v1.0.0
 * @author: liaozuliang
 * @date: 2021/9/17 18:27
 */
@Slf4j
@RestController
public class OrderController implements OrderFeign {

    @Autowired
    private AccountFeign accountFeign;

    @Autowired
    private UserFeign userFeign;

    @Override
    public Result<Boolean> insert(@RequestBody OrderDTO orderDTO) {
        log.info("=====insert======");
        return Result.success(true);
    }

    @Override
    public Result<Boolean> delete(@RequestParam("orderNo") String orderNo) {
        log.info("=====delete======");
        return Result.success(true);
    }

    @Override
    public Result<Boolean> update(@RequestBody OrderDTO orderDTO) {
        log.info("=====update======");
        return Result.success(true);
    }

    @Override
    public Result<OrderDTO> getByOrderNo(@PathVariable("orderNo") String orderNo) {
        log.info("=====getByOrderNo======");
        OrderDTO orderDTO = new OrderDTO();
        orderDTO.setOrderNo(orderNo);
        return Result.success(orderDTO);
    }

    @Override
    public Result<Map<String, Object>> getOrderDetail(@PathVariable("orderNo") String orderNo) {
        log.info("=====getOrderDetail======");

        Result<AccountDTO> accountDTOResult = accountFeign.getByUserId(1L);
        Result<UserDTO> userDTOResult = userFeign.getByUserId(1L);

        OrderDTO orderDTO = new OrderDTO();
        orderDTO.setOrderNo(orderNo);

        Map<String, Object> dataMap = new HashMap<>();
        dataMap.put("order", orderDTO);
        dataMap.put("account", accountDTOResult.getData());
        dataMap.put("user", userDTOResult.getData());

        return Result.success(dataMap);
    }
}
